package Anonymous_study;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
//静态方式实现，  
public class AnonymousDemo3 {
	public static void main(String[]args){
		Random r = new Random();
		List<Hero> heros = new ArrayList<Hero>();
		for(int i = 0;i<100;i++){
			heros.add(new Hero("Hero"+i,r.nextInt(1000),r.nextInt(1000)));
		}
		 System.out.println("初始化后的集合：");
	        System.out.println(heros.toString());
	        System.out.println("使用匿名类的方式，筛选出 hp>100 && damange<50的英雄");
//			filter(heros,a->a.hp>100&&a.damage<50); lambda表达式调用
	        System.out.println("在Lambda表达式中使用静态方法");
	        filter(heros, a -> AnonymousDemo3.testHero(a) );//？
	        System.out.println("直接引用静态方法");
	        filter(heros, AnonymousDemo3::testHero);//？
	}
    public static boolean testHero(Hero h) {
        return h.hp>100 && h.damage<50;
    }
       
	private static void filter(List<Hero> a ,Checker newChecker){
		for(Hero temp :a){
			if(newChecker.test(temp)){
				System.out.println(temp);
			}
		}
	}
}
